package com.jk.controller;

import com.jk.util.OSSUploadUtil;
import org.apache.commons.fileupload.disk.DiskFileItem;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import java.io.File;
import java.io.IOException;
@RestController
@RequestMapping("testOss")
public class TestOss {

    @PostMapping("testOss")
    public String testOss(MultipartFile file){
        /*try {
            f=File.createTempFile("tmp", null);
            file.transferTo(f);
        } catch (HttpException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }*/
        String fileName=file.getOriginalFilename();
        String prefix=fileName.substring(fileName.lastIndexOf(".")+1);
        System.out.println(prefix);
        File f = null;
        try {
            f=File.createTempFile("tmp",null);
            file.transferTo(f);
        } catch (IOException e) {
            e.printStackTrace();
        }
        String url = OSSUploadUtil.uploadFile(f,prefix);
        return url;
    }

}
